/**
 * Created with BlueStream
 * Date: 13. 6. 3
 * Time: 오전 11:45
 * Writer: 강석민
 */

var image_viewDiv;
var startY;
var limitY;

var countDiv;
var countNum = 0;
var moveDirection = 1;

var timerID = 0;

window.onload=function(){

    image_viewDiv = document.getElementById("image_view");
    countDiv = document.getElementById("count");
    startY = image_viewDiv.scrollTop;
    limitY = image_viewDiv.scrollHeight - image_viewDiv.offsetHeight;
    this.initEventListener();
}



function initEventListener(){
    document.getElementById("btn_start").addEventListener("click",function(){


        startMove();

    },false);

    document.getElementById("btn_stop").addEventListener("click",function(){
        stopMove();
    },false);
}

function startMove(){
    timerID = setInterval(moveImage,10);
}

function stopMove(){
    if( timerID != 0 ){
        clearInterval(timerID);
    }
}


function moveImage(){
    countNum += 1*moveDirection;

    image_viewDiv.scrollTop = countNum;
    countDiv.innerText = image_viewDiv.scrollTop.toString()+"/"+image_viewDiv.scrollHeight;

    if( image_viewDiv.scrollTop >= limitY ){
        moveDirection *= -1;
    }

    if( image_viewDiv.scrollTop <= 0 ){
        moveDirection *= -1;
    }


}

